#include"task.h"

void Operation::setImg(Mat src)
{
    _src = src;
}
ArmorOperation::ArmorOperation()
{
    _arm = make_shared<ArmorDetector>();
    _arm->setEnemyColor(BLUE);
}

int ArmorOperation::armorType()
{
    return _arm->getArmorType();
}

ArmorOperation::~ArmorOperation()
{
    
}


bool ArmorOperation::armCenter() 
{
    _arm->loadImg(_src);
    int findEnemy = _arm->detect();
    if(findEnemy==ArmorDetector::ARMOR_NO)
    {
        return false;
    }
    else
    {
        _center = _arm->getCenterPoint(*_arm);
        return true;
    }
}
Point2f ArmorOperation::shootCenter()
{
    if(!armCenter())
    {
        return Point2f(0,0);
    }
    else
    {
        Point aimPoint = _center;
        offsetSolve solver(_center,0);
        aimPoint  = solver.getoffset(_center);
        return aimPoint;
    }
}
BuffOperation::BuffOperation()
{
    _buff = make_shared<BuffDetector>();
}

BuffOperation::~BuffOperation()
{
    
}

bool BuffOperation::buffCenter() 
{
   if( !_buff->detect(_src))
    {
        return false;
    }
    else
    {
        _center = _buff->getCenter();
        return true;
    }
}

Point2f BuffOperation::shootCenter()
{
    if(!buffCenter())
    {
        return Point2f(0,0);
    }
    else
    {
        Point aimPoint = _center;
        offsetSolve solver(_center,0);
        aimPoint  = solver.getoffset(_center);
        return aimPoint;
    }
}

Point2f NoTaskOperation::shootCenter()
{
    return Point2f(320,240);
}


shared_ptr<Operation> ArmorShootFactory::creatTask()
{
    return shared_ptr<ArmorOperation>(new ArmorOperation());
}

shared_ptr<Operation> BuffShootFactory::creatTask()
{
    return shared_ptr<BuffOperation>(new BuffOperation());
}

shared_ptr<Operation>  NoTaskFactory::creatTask()
{
    return shared_ptr<NoTaskOperation>(new NoTaskOperation());
}


